home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: How can I pick out charactors from argv[ ] ?
- Date: 3 Mar 1996 12:24:31 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4hc31v$fi5@sparcserver.lrz-muenchen.de>
- References: <4hbcsh$3do@netnews.ntu.edu.tw>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- antony@public.bta.net.cn (Antony Yandong Chen) writes:
-
- >Hi
-
- >I got this from a C turtorial book:
-
- >main (argc,argv)
- >int argc;
- >char *argv[];
-
- Your C turtorial book seems to be quite old. "Old style" function
- definitions should _not_ be used, except if there is a good
- technical reason (e.g. no ANSI C compiler for the target system).
-
- "Implicit int" functions are bad style even in K&R C, imho. So
- try to see whether your compiler accepts
-
- int main(int argc, char *argv[])
-
- >{
- > printf("argc = %d\n",argc);
-
- You should _not_ access argv[1] if you did not check whether
- argc is greater than 1.
-
- > printf("argv1 = %s\n",argv[1]);
-
- >}
-
- >I could execute it OK, but I couldn't be able to pick out single
- >charactors from string argv[], anybody can tell me how to make it?
-
- argv[1] is the second element in an array of pointers to char.
- If argv[1] exists and points to at least 5 consecutive chars,
- there are at least two semanically equivalent ways to access the
- 5th character:
-
- argv[1][4] or *(argv[1] + 4)
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
- | ua302aa@sunmail.lrz-muenchen.de
-
-